import com.sun.javafx.collections.MappingChange;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        Person person1 = new Person("1");
        Person person2 = new Person("1");



        HashBuck2 hashBuck2_1 = new HashBuck2();
        HashBuck2 hashBuck2_2 = new HashBuck2();

        hashBuck2_1.put(person1,"张三");

        System.out.println(hashBuck2_1.get(person2));
    }



    public static void main3(String[] args) {
        TreeSet<String> set = new TreeSet<>();
        set.add("hello");
        set.add("abc");
        set.add("plo");

        //set里面的元素不能重复
        System.out.println(set);

        for (String s : set) {
            System.out.println(s);
        }
    }

        public static void main2(String[] args) {
        Map<String,Integer> map1 = new TreeMap<>();
        TreeMap<String,Integer> map2 = new TreeMap<>();

        map2.put("this",5);
        map2.put("is",4);
        map2.put("a",9);
        //val值可以更改更新，但key不能直接修改，需要先删除再进行重新插入
        map2.put("a",9999);

        //拿到phe8的val，没有就返回1999
        int val = map2.getOrDefault("phe8",1999);
        System.out.println(val);


        //包含了 Map 对象 map2 中的所有键。通过 keySet() 方法可以获取到 Map 中不包含重复元素的键的集合。
        //通过key的值进行比较
        Set<String> set = map2.keySet();


        //拿到val
        Collection<Integer> collection =  map2.values();

        System.out.println("===");

        Set<Map.Entry<String,Integer>> entries = map2.entrySet();

        //遍历输出map2中的所有元素
        for (Map.Entry<String,Integer> entry  : entries) {
            System.out.println("key: "+entry.getKey()+" value: "+entry.getValue());
        }

    }
    public static void main1(String[] args) {
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        binarySearchTree.insert(3);
        binarySearchTree.insert(1);
        binarySearchTree.insert(5);
        binarySearchTree.insert(4);
        binarySearchTree.insert(6);
        binarySearchTree.insert(8);
        System.out.println("==");


        System.out.println(binarySearchTree.search(5));

        binarySearchTree.remove(5);
        System.out.println("  ");

    }

    //普通方法实现第一个不重复的字符
    public int firstUniqChar1(String s) {
      char[] array = s.toCharArray();
      int i = 0;
      for (; i < array.length; i++) {
          boolean flg = true;
            for (int j = i+1; j < array.length; j++) {
                if(array[i]  == array[j]){
                    flg = false;
                    break;
                }
            }
            if(flg == true) {
                return i;
            }
        }
      return -1;
    }


    public int firstUniqChar2(String s) {
       int[] count = new int[26];
        for (char c: s.toCharArray()) {
            count[c - 'a']++;
        }

        for (int i = 0; i < s.length(); i++) {
            if(count[i -  'a'] == 1){
                return i;
            }
        }
        return -1;
    }



    //使用简单hash表来实现
    public int firstUniqChar(String s) {
        Map<Character, Integer> map = new HashMap<>();
        for (char c : s.toCharArray()) {
            map.put(c, map.getOrDefault(c, 0) + 1);
        }
        for (int i = 0; i < s.length(); i++) {
            if (map.get(s.charAt(i)) == 1) {
                return i;
            }
        }
        return -1;

    }

}
